package com.dhcc.DRGsHosp.web.controller;

import java.util.List;
import java.util.Map;

import org.dayatang.utils.Page;
import org.openkoala.koala.commons.InvokeResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dhcc.DRGsHosp.facade.ScheduleJobFacade;
import com.dhcc.DRGsHosp.facade.dto.ScheduleJobDTO;

/**
 * @ClassName: ScheduleJobController  
 * @Description ：    定时任务管理
 * @Date: 2018年10月12日 上午9:57:44  
 * @Author QiaoYiLong 
 * @Version 3.1.1 DHC-DRG
 */
@Controller("ScheduleJobController20181012")
@RequestMapping("/scheduleJob")
public class ScheduleJobController {
	
	@Autowired
	private ScheduleJobFacade scheduleJobFacade;
	

	@ResponseBody
	@RequestMapping("/isExist")
	public InvokeResult isExist(@RequestParam String jobName) {
		boolean isExist = scheduleJobFacade.isScheduleJobExist(jobName);
		return InvokeResult.success(isExist);
	}
	//取得分页数据
	@ResponseBody
	@RequestMapping("/getPageData")
	public Page pageJson( @RequestParam int page, @RequestParam int pagesize) {
		Page<ScheduleJobDTO> all = scheduleJobFacade.pageQueryScheduleJob( page, pagesize);
		return all;
	}
	//取得所有数据
	@ResponseBody
	@RequestMapping("/getAllData")
	public InvokeResult allData(@RequestParam Map<String,Object> condition) {
		List<Map<String,Object>> resultList =  scheduleJobFacade.findAllByCondition(condition);
		return InvokeResult.success(resultList);
	}
	
	@ResponseBody
	@RequestMapping("/add")
	public InvokeResult add(@RequestParam Map<String,Object> condition) {
		scheduleJobFacade.addJob(condition);
		return InvokeResult.success();
	}
	
	@ResponseBody
	@RequestMapping("/update")
	public InvokeResult update(@RequestParam Map<String,Object> condition) {
		scheduleJobFacade.updateJob(condition);
		return InvokeResult.success();
	}	
	@ResponseBody
	@RequestMapping("/delete")
	public InvokeResult delete(@RequestParam String jobId) {
		scheduleJobFacade.deleteJob(jobId);
		return InvokeResult.success();
	}
	//禁用
	@ResponseBody
	@RequestMapping("/pause")
	public InvokeResult pause(@RequestParam String jobId) {
		scheduleJobFacade.pauseJob(jobId);
		return InvokeResult.success();
	}
	//启用
	@ResponseBody
	@RequestMapping("/resume")
	public InvokeResult resume(@RequestParam String jobId) {
		scheduleJobFacade.resumeJob(jobId);
		return InvokeResult.success();
	}
	//立即执行
	@ResponseBody
	@RequestMapping("/runOnce")
	public InvokeResult runOnce(@RequestParam String jobId) {
		scheduleJobFacade.runOnce(jobId);
		return InvokeResult.success();
	}
}
